<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="sec"
	uri="http://www.springframework.org/security/tags"%>

<sec:authentication property="principal" var="currentPrincipal"
	scope="page" />

<div class="modal-dialog x-modal-dialog" style="width: 600px;">

	<div class="modal-content">

		<div class="modal-header x-breadcrumb clearfix">

			<h2>
				<i class="glyphicon glyphicon-fire" title=""></i>&nbsp;&nbsp;<span>更改课时</span>
			</h2>

			<button type="button" class="close" data-dismiss="modal">&times;</button>

		</div>

		<form class="form-horizontal" method="POST"
			action="${ctx.host}/schedules/calendar-edit" data-validate="true">

			<input type="hidden" name="_method" value="PATCH"> <input
				type="hidden" name="coach" value="${coachId}"> <input
				type="hidden" name="date" value="${date}">
			<div class="modal-body">

				<div class="form-group x-form-group">
					<label class="col-xs-3 control-label">休息类型</label>
					<div class="col-xs-7" style="width: 60%;">
						<select name="type" class="form-control select2"
							data-validate="required">
							<option></option>
							<option value="business">公出</option>
							<option value="duty">值班</option>
							<option value="conference">会议</option>
							<option value="training">培训</option>
						</select>
					</div>

				</div>

				<div class="form-group x-form-group hide business-hour">

					<label class="col-xs-3 control-label">日期</label>
					<div class="col-xs-7" style="width: 60%; margin-bottom: 25px">
						<c:set var="businessCalendars"
							value="${persist.coachRestCalendars(coachId,date)['business']}" />
						<select name="businessDays" class="form-control select2" multiple>
							<option></option>
							<c:forEach var="date" items="${remainDays}">
								<option value="${date}">${date}</option>
							</c:forEach>
						</select>
					</div>

					<label class="col-xs-3 control-label">时间</label>
					<div class="col-xs-7" style="width: 60%;">
						<c:set var="businessCalendars"
							value="${persist.coachRestCalendars(coachId,date)['business']}" />
						<select name="businessHour" class="form-control select2" multiple>
							<option></option>
							<c:forEach var="freeTime"
								items="${persist.freeScheduleTime(coachId, date, siteId, 'business')}">
								<c:choose>
									<c:when test="${day > today}">
										<option value="${freeTime}"
											${persist.containRestTime(businessCalendars,freeTime) ? 'selected' : ''}>${freeTime}</option>
									</c:when>
									<c:when
										test="${day == today and persist.compareHour(freeTime)}">
										<option value="${freeTime}"
											${persist.containRestTime(businessCalendars,freeTime) ? 'selected' : ''}>${freeTime}</option>
									</c:when>
								</c:choose>
							</c:forEach>
						</select>
					</div>

				</div>

				<div class="form-group x-form-group hide duty-hour">

					<label class="col-xs-3 control-label">日期</label>
					<div class="col-xs-7" style="width: 60%; margin-bottom: 25px">
						<c:set var="businessCalendars"
							value="${persist.coachRestCalendars(coachId,date)['business']}" />
						<select name="businessDays" class="form-control select2" multiple>
							<option></option>
							<c:forEach var="date" items="${remainDays}">
								<option value="${date}">${date}</option>
							</c:forEach>
						</select>
					</div>

					<label class="col-xs-3 control-label">时间</label>
					<div class="col-xs-7" style="width: 60%;">
						<c:set var="dutyCalendars"
							value="${persist.coachRestCalendars(coachId,date)['duty']}" />
						<select name="dutyHour" class="form-control select2" multiple>
							<option></option>
							<c:forEach var="freeTime"
								items="${persist.freeScheduleTime(coachId, date, siteId, 'duty')}">
								<c:choose>
									<c:when test="${day > today}">
										<option value="${freeTime}"
											${persist.containRestTime(dutyCalendars,freeTime) ? 'selected' : ''}>${freeTime}</option>
									</c:when>
									<c:when
										test="${day == today and persist.compareHour(freeTime)}">
										<option value="${freeTime}"
											${persist.containRestTime(dutyCalendars,freeTime) ? 'selected' : ''}>${freeTime}</option>
									</c:when>
								</c:choose>
							</c:forEach>
						</select>
					</div>
				</div>

				<div class="form-group x-form-group hide conference-hour">

					<label class="col-xs-3 control-label">日期</label>
					<div class="col-xs-7" style="width: 60%; margin-bottom: 25px">
						<c:set var="businessCalendars"
							value="${persist.coachRestCalendars(coachId,date)['business']}" />
						<select name="businessDays" class="form-control select2" multiple>
							<option></option>
							<c:forEach var="date" items="${remainDays}">
								<option value="${date}">${date}</option>
							</c:forEach>
						</select>
					</div>

					<label class="col-xs-3 control-label">时间</label>
					<div class="col-xs-7" style="width: 60%;">
						<c:set var="conferenceCalendars"
							value="${persist.coachRestCalendars(coachId,date)['conference']}" />
						<select name="conferenceHour" class="form-control select2"
							multiple>
							<option></option>
							<c:forEach var="freeTime"
								items="${persist.freeScheduleTime(coachId, date, siteId, 'conference')}">
								<c:choose>
									<c:when test="${day > today}">
										<option value="${freeTime}"
											${persist.containRestTime(conferenceCalendars,freeTime) ? 'selected' : ''}>${freeTime}</option>
									</c:when>
									<c:when
										test="${day == today and persist.compareHour(freeTime)}">
										<option value="${freeTime}"
											${persist.containRestTime(conferenceCalendars,freeTime) ? 'selected' : ''}>${freeTime}</option>
									</c:when>
								</c:choose>
							</c:forEach>
						</select>
					</div>
				</div>

				<div class="form-group x-form-group hide training-hour">

					<label class="col-xs-3 control-label">日期</label>
					<div class="col-xs-7" style="width: 60%; margin-bottom: 25px">
						<c:set var="businessCalendars"
							value="${persist.coachRestCalendars(coachId,date)['business']}" />
						<select name="businessDays" class="form-control select2" multiple>
							<option></option>
							<c:forEach var="date" items="${remainDays}">
								<option value="${date}">${date}</option>
							</c:forEach>
						</select>
					</div>
					
					<label class="col-xs-3 control-label">时间</label>
					<div class="col-xs-7" style="width: 60%;">
						<c:set var="trainingCalendars"
							value="${persist.coachRestCalendars(coachId,date)['training']}" />
						<select name="trainingHour" class="form-control select2" multiple>
							<option></option>
							<c:forEach var="freeTime"
								items="${persist.freeScheduleTime(coachId, date, siteId, 'training')}">
								<c:choose>
									<c:when test="${day > today}">
										<option value="${freeTime}"
											${persist.containRestTime(trainingCalendars,freeTime) ? 'selected' : ''}>${freeTime}</option>
									</c:when>
									<c:when
										test="${day == today and persist.compareHour(freeTime)}">
										<option value="${freeTime}"
											${persist.containRestTime(trainingCalendars,freeTime) ? 'selected' : ''}>${freeTime}</option>
									</c:when>
								</c:choose>
							</c:forEach>
						</select>
					</div>
				</div>

			</div>

			<div class="modal-footer">
				<button type="submit"
					class="btn btn-success btn-shadow btn-shadow-success x-btn">确定</button>
				&nbsp;&nbsp;&nbsp;&nbsp;
				<button type="button"
					class="btn btn-default btn-shadow btn-shadow-default x-btn"
					data-dismiss="modal">取消</button>
			</div>

		</form>

	</div>

    </div>

<script type="text/javascript">
	$(function() {

		$('.select2').select2({
			placeholder : '请选择',
			minimumResultsForSearch : -1,
			allowClear : true,
			width : '100%'
		});
	})
</script>
